package statistics

import (
	"admin100/app/model"
	"admin100/app/service"
	"admin100/library/define"
	"admin100/library/define/defErr"
	"admin100/library/response"
	"strings"

	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

var ChargeMgr = chargeMgrApi{}

type chargeMgrApi struct{}

func (a *chargeMgrApi) RegRecharge(r *ghttp.Request) {
	var req = model.DailyLTVReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}

	data := service.Charge.GetDailyLTVListV1(&req)
	response.JsonSuc(r, g.Map{"rows": data})
}

func (a *chargeMgrApi) GetDailyLtv(r *ghttp.Request) {
	var req = model.DailyLTVReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}

	data := service.Charge.GetDailyLTVListV1(&req)
	response.JsonSuc(r, g.Map{"rows": data})
}

func (a *chargeMgrApi) Statistics(r *ghttp.Request) {
	var req = model.StatisticsReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}
	data := service.Charge.Statistics(req.PlatformId, req.ServerId, strings.Split(req.ChannelList, ","))
	response.JsonSuc(r, g.Map{"rows": data})
}

func (a *chargeMgrApi) IncomeStatistics(r *ghttp.Request) {
	var req = model.DailyStatisticsReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}
	response.JsonSuc(r, service.Charge.GetIncomeStatisticsChartData(&req))
}

// 充值金额分布
func (c *chargeMgrApi) ChargeMoneyDistribution(r *ghttp.Request) {
	var req = model.ChargeMoneyDistributionReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}
	response.JsonSuc(r, g.Map{"rows": service.Charge.GetChargeMoneyDistributionV1(&req)})
}

// 充值等级分布
func (c *chargeMgrApi) ChargeLevelDistribution(r *ghttp.Request) {
	var req = model.ChargeLevelDistributionReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}

	response.JsonSuc(r, g.Map{"rows": service.Charge.GetChargeLevelDistributionV1(&req)})
}

// 充值活动分布
func (c *chargeMgrApi) ChargeActivityDistribution(r *ghttp.Request) {
	var req = model.ChargeActivityDistributionReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}
	response.JsonSuc(r, g.Map{"rows": service.Charge.GetChargeActivityDistribution(&req)})
}

// 充值任务分布
func (c *chargeMgrApi) ChargeTaskDistribution(r *ghttp.Request) {
	var req = model.ChargeTaskDistributionReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}

	response.JsonSuc(r, g.Map{"rows": service.Charge.GetChargeTaskDistribution(&req)})
}

// 获取充值排行榜
func (c *chargeMgrApi) ChargeRankList(r *ghttp.Request) {
	var req = model.ChargeRankReq{}
	if err := r.ParseForm(&req); err != nil {
		defErr.Panic(define.Fail, err.Error())
	}

	res, total := service.Charge.GetChargeRankList(&req)
	response.JsonSuc(r, g.Map{"rows": res, "total": total})
}
